#include <iostream>          //递归
using namespace std;
void hanoi(int n, int a, int b, int c)
{
    if(n > 0)
    {
        hanoi(n-1, a, c, b);
        cout << "move " << a << " to " << b << endl;
        hanoi(n-1, c, b, a);
    }
} 
int main()
{
    int n;
    cin >> n;
    hanoi(n, 1, 2, 3);
    return 0;
}

#include <iostream>           //非递归
#include <stack>  
using namespace std; 

struct hanoiunrec  
{ 
    hanoiunrec();
    hanoiunrec(int n, char a, char b, char c):_n(n), _x(a), _y(b), _z(c){}          //构造函数 
    int _n;         
    char _x, _y, _z;     
};  

void hanoi(int n, char x, char y, char z)  
{  
    stack<hanoiunrec> s;    
    s.push(hanoiunrec(n, x, y, z));   
    while (!s.empty())         
    {  
        hanoiunrec q = s.top();     
        s.pop();          
        n = q._n;         
        x = q._x;  
        y = q._y;  
        z = q._z;  
        if (n == 1)           
        {  
            cout << "Move " << q._x << " to " << q._z << endl;  
        }  
        else  
        {  
            s.push(hanoiunrec(n - 1, y, x, z));      
            s.push(hanoiunrec(1, x, y, z));  
            s.push(hanoiunrec(n - 1, x, z, y));  
        }  
    }  
}
